//
//  CityTableViewController.m
//  QuickCure
//
//  Created by 源 何 on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "CityTableViewController.h"

@interface CityTableViewController ()

@end

@implementation CityTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.barTintColor = kThemeColor;
    
    self.title = @"选择当前城市位置";
    
    [self setUpLeftButtonItem];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"city"];
}

- (void)setUpLeftButtonItem{
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,50, 50)];
    
    [leftBtn setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
}

/*!
 *  如果想任意跳转，就重写goBack方法
 */
- (void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.cityArray.count;
}

//cell内容复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"city" forIndexPath:indexPath];
    
    cell.textLabel.text = self.cityArray[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *tempStr = self.cityArray[indexPath.row];
    
//    NSLog(@"%@",tempStr);
    
    if (self.cityBlock) {
        
        self.cityBlock(tempStr);
    }
    
    //跳转到根控制器
    [self.navigationController popToRootViewControllerAnimated:YES];
}

@end
